﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Data;
using Ersur.DevTeam;

namespace Ersur
{
    public partial class OrderReport : XtraReport
    {
        string detailTableName;
        public OrderReport(DataSet sourceData) //,bool secondCopy = false)
        {
            InitializeComponent();
            //SecondCopy = secondCopy;

            ds = sourceData;
            detailTableName = ds.Tables[1].TableName;

            DataRow dr = ds.Tables[0].Rows[0];
            tcBrand.Text = dr["Brand"].ToString();
            tcContact.Text = dr["Contact"].ToString();
            tcAdres.Text = dr["Address"].ToString();
            tcPhone.Text = dr["Phone"].ToString();
            tcFair.Text = dr["Fair"].ToString();
            tcReference.Text = dr["Reference"].ToString();
            lblNot.Text = dr["Notes"].ToString();
            tcSeason.Text = dr["Season"].ToString();
            tcMail.Text = dr["Email"].ToString();
            tcPrivateNotes.Text = dr["PrivateNotes"].ToString();

            //if (!SecondCopy)
            {
                trPrivate.Visible = false;
                lblPrivate.Visible = false;
            }

            if (Settings.Currency == "$")
                lblFob.Text = lblFob.Text.Replace("€", "$");

            xrCancelled.Visible = (bool)dr["Cancelled"];
            
            ds.Tables[1].Columns.Add("RowNo", typeof(int));
            
            
            DataRowCollection rows = ds.Tables[1].Rows;
            for (int i = 0; i < rows.Count; i++ )
                rows[i]["RowNo"] = i + 1;                
            
            if (dr["EditDate"] != DBNull.Value)
                tcDate.Text = ((DateTime)dr["EditDate"]).ToString("dd.MM.yyyy HH:mm");
            else
                tcDate.Text = xrDate.Text = "";

        }

       // bool SecondCopy = false;


        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            this.DataSource = ds;
            this.DataMember = detailTableName;

            BindCell(detailRN, "RowNo");
            BindCell(detailArticle, "Article");
            BindCell(detailColour, "Colour");
            BindCell(detailBall, "BallSize");
            BindCell(detailCount, "Count","{0:n}");
            BindCell(detailComposition, "Composition");
            BindCell(detailMin, "MinDYELot");
            BindCell(detailFob, "Price", "{0:n}");            
            BindCell(detailNotes, "Notes");
        }

        private void BindCell(XRTableCell cell, string columnName, string format = "")
        {
            if (format == "")
                cell.DataBindings.Add("Text", null, detailTableName + "." + columnName);
            else
                cell.DataBindings.Add("Text", null, detailTableName + "."+ columnName, format);
        }

      
    }
}